Computer systems often use databases to store and manage large amounts of data. These databases usually have multiple clients that use and manipulate this data. Clients typically manipulate data in the form of various "read" and "write" operations that either allow the client to retrieve data from the database or allow the client to modify data in the database. A typical client transaction may have several read and write operations, and in a database, it is common for many transactions to concurrently execute to improve processing efficiency. In such a case, if access to the database by each transaction is allowed freely, the consistency among the data can be jeopardized.
It is common for many database clients, or multiple procedures on a single client machine, to seek concurrent access to a database system in order to read data from the database and write data to the database. However, each client needs to interact with the database free from the interference of others. That is, during the course of a client's transaction to the database--reading and modifying a set of data from the database--that portion of the database must remain unchanged by other clients. To prevent this problem, concurrency control is used by database systems to govern concurrent access to the database system. It ensures the integrity of each transaction in a multi-user environment.
One type of concurrency control is "optimistic concurrency control." Optimistic concurrency control means that the check point for collisions between transactions is at the end of a transaction. With optimistic concurrency control, it is assumed that a transaction will finish before another transaction attempts to change the same data. The transaction reads the necessary data, internally makes its data updates, and finally determines if any of the data has changed before writing the updates to the database. When the client is ready to actually commit its data modifications to the database, the system checks if that data has been modified by any other transaction since the time the client's transaction first read the data. If there has been no change to the particular data, then the client's transaction can complete. If any data has been changed, then the system rolls back the client's updates and notifies the client so that it can retry its transaction, if desired. A "roll back" refers to the transaction being canceled and all data being restored to its original state before the transaction started. While optimistic concurrency control can provide significant performance improvement by avoiding the delay of initially securing the data, it is also possible that the system must roll back a transaction if another process modifies the same data.
Referring now to object-oriented systems and programming languages, such systems use "classes" containing both data members that store data and function members (or methods) that act upon the data. Classes form templates for the creation of "objects," representing instances of a class. Classes also define methods, which are procedures that operate on objects of the same class. An exemplary object-oriented programming language is the Java.TM. programming language described in "The Java Programming Language," Ken Arnold, James Gosling, Addison-Wesley, 1996, which is incorporated herein by reference. For further description of the Java language, refer to "The Java Language Specification," James Gosling, Bill Joy, Guy Steele, Addison-Wesley, 1996, which is incorporated herein by reference.
When accessing databases in object-oriented systems, some systems use "lock groups" to implement optimistic concurrency control. With reference to optimistic concurrency control, a lock group, despite its name, does not refer to locking blocks of data. Instead, a lock group provides a collision detection mechanism. In particular, lock groups specify one or more fields to be modified by only one client during a transaction by that client. Lock groups are thus useful for managing data in a database. For example, if a customer object includes fields for a customer name and address, a lock group may specify the name and address fields so that, for example, one client does not change the data in the name field while another client changes data in the corresponding address field. In other words, the data in the name and address fields can only be changed by one client during a transaction to avoid, for example, an incorrect address being entered for a particular name.
Lock groups are used to determine conflicts when a client commits the transaction. When a client performs a transaction modifying data in a particular object and attempts to commit the transaction to save the modifications, the system determines if any lock groups include any of the modified fields, and if so, it further determines if any other application modified any field of those lock groups. The system does not commit the transaction and modify the database if another client made such modifications.
A conventional lock group includes all fields in an object. However, objects may include many fields and a client will often only modify a small set of fields in an object. Many conflicts occur when a lock group contains a large number of fields because only one client may modify data in an entire object during a transaction, which effectively prevents other clients from modifying any data in the object during the transaction.
Conventional object-oriented systems using optimistic concurrency control to access a database do not allow the client to modify some fields of an object without stopping other transactions from simultaneously modifying other fields in the same object. In conventional systems, if one transaction modifies a field of an object, no other transaction may modify another field in the same object. Consequently, conventional systems do not allow a field to simultaneously belong to more than one lock group. Additionally, conventional lock groups do not contain fields of different classes. These limitations slow the system by stopping different applications from simultaneously accessing different fields of the same object. It is therefore desirable to improve such systems.